<template>
	<view>
		<view style="font-size:28rpx;line-height:20px;color: #999;padding:20px;">提示：配置参数保存后，前端预计10分钟左右生效。</view>
		<view class="uni-container" style="float: left;">
			<span>跳转到应用市场详情页</span>
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="appStore下载地址最后id" name="title" labelWidth="150">
					<input class="uni-input-border" type="text" v-model="gotomarket.iosMarketId" style="width: 400px;" />
				</uni-forms-item>
				<uni-forms-item label="Android上架应用市场的下载链接" name="title" labelWidth="150">
					<input class="uni-input-border" type="text" v-model="gotomarket.androidMarketUrl" style="width: 400px;" />
				</uni-forms-item>
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading" style="width: 300px;"
						@click="save">保存</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isLoading: false,
				"gotomarket": {
					"iosMarketId": "",
					"androidMarketUrl": ""
				}
			}
		},
		mounted() {
			this.getinfo()
		},
		methods: {
			getinfo() {
				this.isLoading = true
				uni.showLoading({
					title: '加载中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/loadconfig",
						data: {
							id: 'gotomarket'
						}
					}
				}).then((res) => {
					console.log(res, "get--------------")
					this.gotomarket = res.result.config
					uni.hideLoading();
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			},
			save() {
				this.isLoading = true
				delete this.gotomarket._id;
				console.log("this.gotomarket: ",this.gotomarket);
				for (let key in this.gotomarket) {
					if (key != '_id') {
						this.gotomarket[key] = this.gotomarket[key]
					}
				}
				console.log(this.gotomarket, "-----------")
				uni.showLoading({
					title: '保存中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/setconfig",
						data: {
							json: JSON.stringify({
								gotomarket: this.gotomarket
							})
						}
					}
				}).then((res) => {
					console.log(res, "save-------------")
					this.isLoading = false
					uni.hideLoading();
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style>

</style>
